<div class="panel-manage">
	<div class="navbar navbar-inverse">
		<div class="navbar-inner text-right">
		    <button id="btn-info-save" class="btn btn-primary">บันทึก</button>
		</div>
	</div>
	<div class="panel-message"></div>	
	<div>		
		<form id="frm-info" method="post" action="<?php print base_url() . $cafe_name; ?>/backend/general/info/ajax_save">
			<div class="line-space">
				<div class="well well-small"><b>ระบุชื่อร้านค้า</b></div>
				<div class="row-fluid section">					
					<label class="control-label span4">ชื่อร้าน</label>				
					<div class="span8">
						<div class="controls">
							<input type="text" name="tct" style="width:400px;" value="<?php print strip_tags($cafe_title); ?>" /><br />
						</div>
					</div>
				</div>
				<div class="row-fluid section">					
					<label class="control-label span4">URL</label>					
					<div class="span8">
						<div class="controls">						
							<a href="<?php print base_url() . $cafe_name ?>" target="_blank"><?php print base_url() . $cafe_name ?></a>
						</div>
					</div>
				</div>	
				<div class="row-fluid section">					
					<label class="control-label span4">สถานะร้านเปิดร้าน</label>					
					<div class="span8">
						<div class="controls">
							<div class="switch switch-small" id="switch-state" data-on="success" data-off="danger">
								<?php if ($cafe_status): ?>
							    	<input type="checkbox" checked />
							    <?php else: ?>
							    	<input type="checkbox"  />
							    <?php endif; ?>
							</div>
						</div>
						<div class="alert alert-info" style="margin-top:10px;"><p><i class="icon-info-sign"></i>
							<small>หากท่านตั้งสถานะปิดร้าน ผู้ใช้งานจะไม่ดูหน้าร้านค้าได้ รวมถึงข้อมูลร้านจะไม่ถูกแสดงที่ผลลัพท์การค้นหา</small></p>
						</div>
					</div>					
				</div>						
			</div>			
			<div class="line-space">
				<div class="well well-small"><b>ส่วนเสริม</b></div>
				<div class="row-fluid section">
					<label class="span4">ออฟชั่น</label>		
					<div class="span8">
						<ul class="unstyled">				
							<?php if (count($data) > 0):						
									for ($i=0; $i<count($data); $i++):
										if ($data[$i]['SET']): ?>
											<label class="checkbox">
												<input type="checkbox" name="chk-ct[]" value="<?php print $data[$i]['CAF_T_ID']; ?>" checked>
												<?php print $data[$i]['CAF_T_TITLE']; ?>
											</label>									
									<?php else:?>
											<label class="checkbox">
												<input type="checkbox" name="chk-ct[]" value="<?php print $data[$i]['CAF_T_ID']; ?>">
												<?php print $data[$i]['CAF_T_TITLE']; ?>
											</label>									
									<?php endif; ?>
								<?php endfor; ?>				
							<?php endif; ?>					 
						</ul>
					</div>	
				</div>			
			</div>	
			<div class="line-space">
				<div class="well well-small"><b>อื่นๆ</b></div>
				<div class="row-flud section">
					<div class="span4">
						<label>Facebook</label>						
					</div>
					<div class="span8">						
						<input type="text" name="tf" value="<?php print $cafe_facebook; ?>" />											
					</div>
				</div>
				<div class="row-flud section">
					<div class="span4">
						<label>เว็บไซต์</label>						
					</div>
					<div class="span8">												
						<input type="text" name="tw" value="<?php print $cafe_website; ?>" />						
					</div>
				</div>				
			</div>
			
		</form>	
	</div>
</div>
<script type="text/javascript">	
	$(function(){		
		$('#switch-state').on('switch-change', function (e, data) {			    
		    $.post('<?php print base_url() . $cafe_name . '/backend/general/info/ajax_change_state'; ?>', { s : data.value }, function(output){
		    	  	
			    switch (output.result){
				    case -2: case -1:{				    	
				    	var html = '<div class="alert alert-error">';
						html += '<button type="button" class="close" data-dismiss="alert">&times;</button>';
						html += output.message + '</div>';
							
						$('.panel-message').html(html);
						setTimeout(function(){ window.location.href = output.redirect_url; },2000)
				    }
				    break;
			    }
		    }, 'json');
		});
		
		$('#btn-info-save').click(function(){
			$('#frm-info').ajaxSubmit({				
				async	: false,				
				success	: function(output){
									
					output = JSON.parse(output);
					switch (output.result){
						case -1: case -2:{
							alert(output.message);
							window.location.href = output.redirect_url;
						}
						break; 
						default:{
							var html;
							if (output.result)
								html = '<div class="alert alert-success">';						
							else 
								html = '<div class="alert alert-error">';					

							html += '<button type="button" class="close" data-dismiss="alert">&times;</button>';
							html += output.message + '</div>';
							$('.panel-message').html(html);

							autoclosealert('.alert', 2000);
						}
						break;
					}
				}
			});
		});
	});
</script>